package com.zb.admin.controller;

import com.zb.admin.service.AdSensitiveService;
import com.zb.model.common.PageResult;
import com.zb.model.common.Result;
import com.zb.model.dto.admin.SensitiveDTO;
import com.zb.model.pojo.admin.AdSensitive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/sensitive")
public class AdSensitiveController{

    @Autowired
    private AdSensitiveService adSensitiveServicel;
//    敏感词查询
    @GetMapping("/list")
    public Result list(SensitiveDTO dto) {
        PageResult list = adSensitiveServicel.list(dto);
        return Result.SUCCESS(list);
    }

//    敏感词添加
    @PostMapping("/save")
    public Result insert(@RequestBody AdSensitive adSensitive) {
        Integer num = adSensitiveServicel.save(adSensitive);
        if(num > 0) {
           return Result.SUCCESS("添加成功");
        }else {
            return  Result.ERROR();
        }
    }

//    敏感词修改
    @PutMapping("/update")
    public Result update(@RequestBody AdSensitive adSensitive) {
        Integer num = adSensitiveServicel.update(adSensitive);
        if(num > 0) {
            return Result.SUCCESS("更新成功");
        }else {
            return  Result.ERROR();
        }
    }

//    敏感词删除
    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        Integer num = adSensitiveServicel.Del(id);
        if(num > 0) {
            return Result.SUCCESS("删除成功");
        }else {
            return  Result.ERROR();
        }
    }

    //    根据ID查询敏感词
    @GetMapping("/{id}")
    public Result getDetail(@PathVariable("id") Integer id) {
        AdSensitive adSensitive = adSensitiveServicel.getById(id);
        return Result.SUCCESS(adSensitive);

    }
}
